package com.snimay.app.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.snimay.app.user.repository.UserRepository;
import com.snimay.app.user.vo.User;
import com.snimay.common.RestServiceController;
import com.snimay.util.ToWeb;

/**   
 * @Title      : UserController.java
 * @Package    : com.snimay.users.controller
 * @Description: TODO 
 * @author     : xxy
 * @date       : 2018年4月27日 下午2:06:47
 * @version    : V1.0   
 */
@RestController
@RequestMapping("user")
public class UserController implements RestServiceController<User, Long>{
	
	@Autowired
	UserRepository repository;

	@Override
	@GetMapping("/{id}")
	public Object getOne(@PathVariable("id") Long id) {
		ToWeb toweb = new ToWeb();
		toweb.setObjData(repository.findOne(id));
		return new Gson().toJson(toweb);
	}

	/**
	 * @Description: TODO
	 * @author     : xxy
	 * @param rowSize
	 * @param page
	 * @return
	 * @throws
	 */
	@Override
	@GetMapping
	public Object getList(@RequestParam(value = "rowSize",defaultValue = "100", required = false) Integer rowSize
            , @RequestParam(value = "page", defaultValue = "1", required = false) Integer page) {
		ToWeb toweb = new ToWeb();
		toweb.setObjData(repository.findAll());
		return new Gson().toJson(toweb);
	}

    @Override
	@PostMapping
	public Object postOne(User entity) {

		// TODO Auto-generated method stub
		System.out.println(entity);
		return null;
	}

	@Override
	public Object putOne(Long id, User entity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object patchOne(Long id, User entity) {
		// TODO Auto-generated method stub
		System.out.println(id);
		return null;
	}

/*	@RequestMapping(value="",method=RequestMethod.DELETE)
	@DeleteMapping
	@*/
	@Override
	public Object deleteOne(Long id) {
		// TODO Auto-generated method stub
		System.out.println(id);
		return null;
	}
	 

}
